package  com.game.raceroom.player.skill
{
	import flash.display.Bitmap;
	import flash.utils.getTimer;
	
	import com.util.ImgUtil;
	import com.game.raceroom.SkillCanvas;
	import com.game.raceroom.Room;
	import com.game.raceroom.events.GameEventDispatcher;
	import com.game.raceroom.player.item.BaseItem;
	public class Skill
	{
	     //冲击 加速提高100%持续5秒,移除当前侧滑效果
	     public static var SKILL_TYPE_STRICK:int=11000;
	     //跳跃
	     public static var SKILL_TYPE_JUMP:int=11010;
	     //快速修理
	     public static var SKILL_TYPE_REPAIR:int=11030;
	     //持续修理
	     public static var SKILL_TYPE_REPAIR_CONTINUE:int=3;
	     //稳固，侧滑效果消失 持续XX秒
	     public static var SKILL_TYPE_FIXING:int=4;      
	     //灵巧，转向度提高XX 持续XX秒
	     public static var SKILL_TYPE_SENSITIVE:int=5; 
	     //隐身 持续XX秒 碰撞后失效
	     public static var SKILL_TYPE_HIDE:int=11020; 	     	     	     
	     //消除冷却
	     public static var SKILL_TYPE_FOCUS:int=11040; 	    
	     //爆弹
	     public static var SKILL_TYPE_BOMB:int=11050; 
	     
	     
         public var item:BaseItem;
         public var icon:Bitmap=new Bitmap;
         //动作施放者
         public var initiator:String;
         public var startTime:Number;
         public var maxTime:int=0;
         public var valid:Boolean=true;
         public var coldTime:int;
         public var maxColdTime:int;
         public var hotkey:int;
         public var skillName:String;
         public var skillType:int;
         public var iconX:int=690;
         public var room:Room;
         public var cold1:Boolean=false;
         public var castStr:int=1;
         public var itemCount:int;
         private var canvas:SkillCanvas;
        
	    public function initHotkey(canvas:SkillCanvas):void{
	    	this.canvas=canvas;
 
	    	icon.bitmapData=ImgUtil.getAnyItemIcon(item).bitmapData;
	        icon.smoothing=true;
            icon.width=38;
            icon.height=38;
	    	itemCount=room.actorInfo.bag.getItemCount(item.iid);
	    	refreshItemCount();
	 
	    }
	    private function refreshItemCount(){
	    	if(itemCount<=0){
	    		itemCount=0;
	    		icon.alpha=0.4;
	    		canvas.itemCount="0";
	    	}else{
	    		if(itemCount>99){
	    			canvas.itemCount="∞";
	    		}else{
	    			canvas.itemCount=itemCount+"";
	    		}
	    	}
	    }
	    public var cold:Boolean=false;
	    public static var lastSpellTime:Number=0;
	    public function castSkill():void{
	    	if(!room.started)return;
            if(room.skillBar.lock)return;
	    	if(itemCount<=0)return; 
	    	if(room.tempSkill>=0)return;
	    	if(room.actorContrl.now_str-castStr<0)return;
            if(cold)return;
	    	if(getTimer()-lastSpellTime<100)return;
	    	cold=true;
	    	lastSpellTime=getTimer();
            
 	    	 spell();
 	    	var str:int=room.actorContrl.now_str-castStr;
     	    room.actorContrl.refStr(str);	 
            room.tempSkill=skillType;
            //trace('set skill'+ skillType);
	        room.events.dispatch(GameEventDispatcher.ON_SKILL, this);	
	    }
	    public function spell():void{
	    	itemCount--;
	    	room.actorInfo.bag.removeOneItem(item.iid);
	    	refreshItemCount();
	    	 //trace('sspell skill'+ skillType);
	    	if(icon.alpha==1){
	    		//trace('sspell alpha 0.3');
	    		icon.alpha=0.3;
	    		this.coldTime=0;
	    		this.startTime=getTimer();
	    	}
	    }
         var time:int;
	    public function update():void{
	    	if(itemCount<=0)return; 
	    	if(icon.alpha!=1){
	    		this.coldTime=getTimer()-this.startTime;
	    		time=Math.floor((maxColdTime-coldTime)/1000.0);
	    		canvas.coldTime=time+"";
	    		if(this.coldTime>this.maxColdTime){
	    			
	    			
	    			//canvas.coldTime.visible=false;
	    			coldDown();
	    		}
	    	}
	    }
	    public function coldDown():void{
	    	 icon.alpha=1;
	    	 canvas.coldTime="";
	    	 coldTime=0;
	    	 cold=false;
	    	 trace('cold down '+this.skillType);
	    }
	    public function setItem(itm:BaseItem){
	    	item=itm;

	    }
 
	}
}